class HotelImagesController < ApplicationController
  # GET /hotel_images
  # GET /hotel_images.json

  layout 'admin'

  def index
    if params[:hid]
      @hotel_images = HotelImage.where('hotel_id =?', params[:hid])
      @hotel_image = HotelImage.new
      respond_to do |format|
        format.js { render layout: false }
      end
    end
  end

  # GET /hotel_images/1
  # GET /hotel_images/1.json
  def show
    @hotel_image = HotelImage.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @hotel_image }
    end
  end

  # GET /hotel_images/new
  # GET /hotel_images/new.json
  def new
    @hotel_image = HotelImage.new

    respond_to do |format|
      format.js { render layout: false }
    end
  end

  # GET /hotel_images/1/edit
  def edit
    @hotel_image = HotelImage.find(params[:id])
  end

  # POST /hotel_images
  # POST /hotel_images.json
  def create
    @hotel_image = HotelImage.new(params[:hotel_image])
    if @hotel_image.save
      @hotel_id = @hotel_image.hotel_id
      @data_check = true
    else
      @data_check = false
    end

    respond_to do |format|
      format.js { render layout: false }
    end
  end

  # PUT /hotel_images/1
  # PUT /hotel_images/1.json
  def update
    @hotel_image = HotelImage.find(params[:id])
    @hotel_image.update_attributes(params[:id])

    respond_to do |format|
      format.js { render layout: false }
    end
  end

  # DELETE /hotel_images/1
  # DELETE /hotel_images/1.json
  def destroy
    @hotel_image = HotelImage.find(params[:id])
    @tr_id = @hotel_image.id
    if @hotel_image.destroy
      @data_check = true
    else
      @data_check = false
    end

    respond_to do |format|
      format.js { render layout: false }
    end
  end

  def destroy_multiple
    Hotel.destroy(params[:hotels_ids])
    @hotels = Hotel.searching(hotel_search)
                         .order(sort_column + ' ' + sort_direction)
                         .paginate(:per_page => 10, :page => params[:page])

    respond_to do |format|
      flash[:notice] = "Selected hotel was successfully deleted."
      format.js { render layout: false }
      format.json { head :no_content }
    end
  end
end
